<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <el-form label-width="80px" :model="form" :rules="rules">
        <el-form-item label="邮箱" prop="email">
          <el-input type="text" v-model="form.email"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <script src="./vue.js"></script>
    <link rel="stylesheet" href="./ele.css" />
    <script src="./index.js"></script>
    <script>
      /*
      自定义表单验证
validator:(rule, value, callback)=>{
    rule:当前验证规则，
    value：当前需要验证项的值，
    callback：如果验证成功  callback()
              如果验证失败 callback(new Error('错误信息'))
}

      */

      new Vue({
        el: "#app",
        data: {
          form: {
            email: "",
          },
          rules: {
            email: [
              { required: true, message: "请输入邮箱", trigger: "change" },
              {
                validator: (rule, value, callback) => {
                  window.console.log(rule);
                  window.console.log(value);
                  let reg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
                  if (reg.test(value)) {
                    callback();
                  } else {
                    callback(new Error("请正确输入邮箱地址"));
                  }
                  //   if (value == "123") {
                  //     callback();
                  //   } else {
                  //     callback(new Error("请正确输入邮箱地址"));
                  //   }
                },
              },
            ],
          },
        },
      });
    </script>
  </body>
</html>
